package net.oschina.app.adapter.Explorer;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.ExploreEventBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wei03 on 2017/1/14.
 */

public class ExplorerRecentAdapter extends BaseAdapter {

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = CommonUtils.getInflate().inflate(R.layout.item_explore_activity, parent, false);
        ExplorerRecentHolder explorerRecentHolder = new ExplorerRecentHolder(itemView);
        //将创建的View注册点击事件
        return explorerRecentHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ExplorerRecentHolder explorerRecentHolder = (ExplorerRecentHolder) holder;
        ExploreEventBean.EventBean eventBean = (ExploreEventBean.EventBean) mDatas.get(position);
        Glide.with(CommonUtils.getContext()).load(eventBean.getCover()).into(explorerRecentHolder.mIvPicExplore);
        explorerRecentHolder.mTvDescExplore.setText(eventBean.getTitle());
        explorerRecentHolder.mTvTimeExplore.setText(eventBean.getStartTime());
        explorerRecentHolder.mTvDetailExplore.setText(eventBean.getSpot());
    }

    static class ExplorerRecentHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_pic_explore)
        ImageView mIvPicExplore;
        @BindView(R.id.tv_desc_explore)
        TextView mTvDescExplore;
        @BindView(R.id.tv_time_explore)
        TextView mTvTimeExplore;
        @BindView(R.id.tv_detail_explore)
        TextView mTvDetailExplore;

        ExplorerRecentHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
